package com.flx.at.spring.code.trans.service;

import com.flx.at.spring.code.trans.dao.BankDao;
import com.flx.at.spring.code.trans.dao.UserDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author Fenglixiong
 * @Create 2021/11/11 1:24
 * @Description
 **/
@Slf4j
@Service("moneyService")
public class MoneyServiceImpl implements MoneyService {

    @Autowired
    private BankDao bankDao;
    @Autowired
    private UserDao userDao;

    @Override
    public int reduceMoney(String account, int money) {
        return bankDao.reduceMoney(account,money);
    }

    @Override
    @Transactional
    public int addMoney(String custom, int money) {

        int ret = userDao.addMoney(custom, money);
        return 1;
    }

    @Override
    @Transactional
    public void deal(String name,int money) {
        reduceMoney(name,money);
        addMoney(name,money);

    }

}
